package main;
import java.awt.Color;

/**
 * Colony object (for gathering resources)
 * @author 12817152
 *
 */
public class Colony {
	private int x;
	private int y;
	private int turnCount;
	private int size=0;
	private int[] cost = {50, 50, 25, 10, 0, 0, 0};

	private BasicMap map;
	Color col = new Color(82, 82, 82); //gray
	Color origCol = col;
	Player owner;
	
	/**
	 * Constructor
	 * @param xpos - x position
	 * @param ypos - y position
	 */
	public Colony(int xpos, int ypos, BasicMap map1, Player p){
		x=xpos;
		y=ypos;
		map=map1;
		owner = p;
	}
	
	/**
	 * sets color
	 * @param c - color
	 */
	public void setColor(Color c) {
		col = c;
	}
	
	/**
	 * gets original color
	 * @return orig color
	 */
	public Color getOrigColor() {
		return origCol;
	}
	
	/**
	 * returns owner
	 * @return owner
	 */
	public Player getOwner() {
		return owner;
	}
	
	/**
	 * @return the turnCount
	 */
	public int getTurnCount() {
		return turnCount;
	}

	/**
	 * @param turnCount the turnCount to set
	 */
	public void setTurnCount(int turnCount) {
		this.turnCount = turnCount;
	}
	
	/**
	 * returns location
	 * @return location in int array
	 */
	public int[] getLocation(){
		int[] location= {x,y};
		return location;
	}
	
	/**
	 * returns color
	 * @return color
	 */
	public Color getColor() {
		return col;
	}

	/**
	 * imcrements turncount and gathers resources on each turn
	 * @return
	 */
	public int[] IncrementTurn(){
		this.turnCount++;
		size=this.getSize();
		return getResources();
	}

	//grows independent of land type
	/**
	 * will find the radial size of the colony.
	 * @return the int size
	 */
	public int getSize(){
		return (int) Math.round(.5*Math.sqrt(turnCount));
	}

	/**
	 * Will return the resources contained within the radius of the colony
	 * @return int[] resource array: wood stone food
	 */
	public int[] getResources(){
		System.out.println(this.size);
		int i=0;
		int[] results= {0,0,0};
		int[] tile;
		for(i=0;i<=this.getSize();i++){
			for(int j=-i; j<=i;j++){
				int ycheckTop=y+size-i; //identifies the y position of the point you're looking at
				int ycheckBot=y-size+i;
				int xcheck=x+j;//identifies the x position of the point you're looking at.
				if(map.exists(xcheck, ycheckTop)){
					tile=map.getLand(xcheck, ycheckTop).getResource();
					results[0]+=tile[0];
					results[1]+=tile[1];
					results[2]+=tile[2];
				}
				if(map.exists(xcheck, ycheckBot)){
					tile=map.getLand(xcheck, ycheckBot).getResource();
					results[0]+=tile[0];
					results[1]+=tile[1];
					results[2]+=tile[2];
				}
					
			}
			
		}
		System.out.println(results[0]+results[1]+results[2]);
		return results;
	}

	/**
	 * @param size the size to set
	 */
	public void setSize(int size) {
		this.size = size;
	}
	
	/**
	 * returns cost
	 * @return
	 */
	public int[] getCost() {
		return cost;
	}
}
